#!/bin/sh

[ \( -d PAL \) -a \( ! $0 -nt .executed \) ] && exit 0

bpp=16
[ -f .8bit ] && bpp=8

for i in PAL NTSC
do
	mkdir -p $i
	rm -f $i/*.pgm $i/*.png

	[ "$i" = "PAL" ] && h=576 || h=480
	./luma -h $h -bpp $bpp > $i/luma01.pgm
	./luma -h $h -bpp $bpp -bands $h > $i/luma02.pgm
	./luma -h $h -bpp $bpp -hmirror 1 > $i/luma03.pgm
	./luma -h $h -bpp $bpp -bands $h -vmirror 1 > $i/luma04.pgm
	./luma -h $h -bpp $bpp -offset 32768 -dmirror 1 > $i/luma05.pgm
	./luma -h $h -bpp $bpp -offset 32768 -dmirror 1 -flip 1 > $i/luma06.pgm
	./luma -h $h -bpp $bpp -offset 32768 -dmirror 1 -quart 1 > $i/luma07.pgm
	./luma -h $h -bpp $bpp -offset 32768 -dmirror 1 -quart 1 -flip 1 > $i/luma08.pgm
	./luma -h $h -bpp $bpp -bands 12 -rband 0 > $i/luma09.pgm
	./luma -h $h -bpp $bpp -bands 12 -rband 0 -rotate 1 -flop 1 > $i/luma10.pgm
	./luma -h $h -bpp $bpp -bands 12 -rband 1 > $i/luma11.pgm
	./luma -h $h -bpp $bpp -bands 12 -rband 1 -vmirror 1 > $i/luma12.pgm
	./luma -h $h -bpp $bpp -bands 12 -rband 1 -rotate 1 -flop 1 > $i/luma13.pgm
	./luma -h $h -bpp $bpp -bands 12 -rband 1 -rotate 1 -vmirror 1 > $i/luma14.pgm
	./luma -h $h -bpp $bpp -offset 32768 -dmirror 1 -hmirror 1 > $i/luma15.pgm
	./luma -h $h -bpp $bpp -type 1 > $i/luma16.pgm
	./luma -h $h -bpp $bpp -type 1 -bands 2 -rband 1 > $i/luma17.pgm
	./luma -h $h -bpp $bpp -type 2 > $i/luma18.pgm
	./luma -h $h -bpp $bpp -type 2 -quart 1 > $i/luma19.pgm
	./luma -h $h -bpp $bpp -type 2 -quart 1 -flip 1 > $i/luma20.pgm
	./luma -h $h -bpp $bpp -type 2 -quart 1 -bands 2 > $i/luma21.pgm
	./luma -h $h -bpp $bpp -type 3 > $i/luma22.pgm

	if [ -f .compress ]
	then 
		for f in $i/*.pgm 
		do
			convert $f $f.png
			rm -f $f
		done
	fi
done

touch .executed

